<script>
// Multistep Options for Like, Share and Proceed
// ->

$(window).on('focus', function () {
  if ($("body").find('#multistep-login').length || $("#multistep-login").is(":visible"))
    location.reload();
});

window.fbAsyncInit = function () {
  FB.init({ appId: '<?php echo $da_config["ms_appid"]; ?>', status: true, cookie: true, xfbml: true });

  FB.getLoginStatus(function (response) {
    if (response.status === 'connected' || response.status === 'not_authorized') {
      $("#multistep-login").remove();
      console.log('logged');
    } else {
      $("#multistep-login").fadeIn();
      console.log('not logged');
    }
  });

  FB.Event.subscribe('edge.create', function (response) {
    $.cookie("fb-lk", "fb_like", { expires: 10, path: '/' });
    multistep_check();
  });
};

(function() {
  var e = document.createElement('script');
  e.type = 'text/javascript';
  e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
  e.async = true;
  document.getElementById('fb-root').appendChild(e);
}());

function fb_callout () {
  FB.ui({
    method: 'feed',
    name: '<?php echo $da_config["ms_title"]; ?>',
    link: '<?php echo $da_config["ms_url"]; ?>',
    picture: '<?php echo $da_config["domain"] . $da_config["ms_image"]; ?>',
    caption: '<?php echo $da_config["ms_caption"]; ?>',
    description: '<?php echo $da_config["ms_description"]; ?>'
  },
  function(response) {
    if (response && response.post_id) {
      $.cookie("fb-sh", "fb_share", { expires: 10, path: '/' });
      multistep_check();
    }
  });
}

function multistep_check () {
  if ( $.cookie('fb-lk') ) {
    $("#multistep-fbl").fadeTo(300, 0.5);
    $("#multistep-like").show();
  }

  if ( $.cookie("fb-sh") ) {
    $("#multistep-share").prop("disabled", true);
  }

  if ( $.cookie("fb-lk") && $.cookie("fb-sh") ) {
    $("#multistep-proceed").fadeTo(300, 1).prop("disabled", false).attr("onClick", "loadGTW()");
  }
} multistep_check();

function loadGTW () {
  alert("trigger your gateway for example");
}

// <-
</script>
